package edu.hrbu.wsdemo.consumer;

import edu.hrbu.wsdemo.bean.Message;
import edu.hrbu.wsdemo.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author xudengyu
 */
@Component
public class NotificationConsumer {

    @Resource
    private SimpMessagingTemplate messagingTemplate;

    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME)
    public void handleMessage(Message message) {
        System.err.println("###2312");
        // 将消息通过 WebSocket 发送到前端
        messagingTemplate.convertAndSend("/topic/notifications", message);
    }
}
